<?php
import('com.yamvc.auth.IAuthAdapter');
/**
* 
*/
class Auth extends AnotherClass
{
	private static $_instance;
	public static function getIsntance(){
		if(self::$_instance==null){
			self::$_instance = new Auth()
		}
		return self::$_instance;
	}
	
	protected $_identity;
	protected $_identityNameSpace='Yamvc_Auth';
	
	public function __construct(){
		
	}
	/**
	 * @return IIdentity
	 */
	public function getIdentity(){
		return $this->_identity;
	}
	
	public function hasIdentity(){
		return $this->_identity!=null;
	}
	
	public function clearIdentity(){
		$this->_identity = null;
	}
	
	public function auth(IAuthAdapter $adapter){
		$this->_setIdentity($adapter->auth());
	}
	
	protected function _setIdentity(IIdentity $identity){
		$this->_identity = $identity;
		Session->getInstance()->$this->_identityNameSpace=$this->_identity;
	}
	
	protected function _restoreIdentity(){
		$identity = Session->getInstance()->$this->_identityNameSpace;
		if($identity instanceof IIdentity){
			$this->_identity = $identity;
		}
		
	}
}

